package menu.lt.pers.menu;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import menu.lt.pers.menu.Bean.HistoryBean;
import menu.lt.pers.menu.Bean.RecipeClassResultBean;
import menu.lt.pers.menu.Bean.UserBean;
import menu.lt.pers.menu.adapter.HistoryRecyclerViewAdapter;
import menu.lt.pers.menu.dao.HistoryDao;

import java.util.ArrayList;
import java.util.List;

public class HistoryActivity extends FragmentActivity  {
    private ArrayList<RecipeClassResultBean.ResultBean.ListBean> materials;
    private RecyclerView recyclerView;
    private HistoryRecyclerViewAdapter adapter;
    private LinearLayoutManager historyManager;
    private UserBean user;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        initView();
        initData();
        updateView();
    }
    private void initView() {
        recyclerView = findViewById(R.id.recyclerView);
    }

    private void initData() {
        user = getIntent().getParcelableExtra("user");
        adapter = new HistoryRecyclerViewAdapter(HistoryActivity.this,user);
        historyManager = new LinearLayoutManager(this);
        historyManager.setOrientation(LinearLayout.VERTICAL);
        historyManager.setSmoothScrollbarEnabled(false);
        recyclerView.setLayoutManager(historyManager);
    }
    private void updateView() {
        recyclerView.setAdapter(adapter);
    }
    public void clear(View view){
        HistoryDao dao = new HistoryDao(this);
        dao.delete();
        adapter.clearList();
    }
}
